package com.hanlink.dsp.protocols;

import com.hanlink.dsp.util.BLog;
import com.hanlink.dsp.util.ByteUtil;
import com.qztech.utils.YzDebug;

/**
 * @author:zhanghb
 * @date:2019/3/9
 * @email:2573475062@qq.com
 **/
public class DeviceProtocol {

    public static byte[] verify() {
        byte[] data = new byte[14];
        int i = 0;
        data[i++] = (byte) 0xaa;
        data[i++] = (byte) 0x55;
        data[i++] = (byte) 0x47;
        data[i++] = 0x45;
        data[i++] = 0x54;
        data[i++] = 0x44;
        data[i++] = 0x53;
        data[i++] = 0x50;
        data[i++] = 0x54;
        data[i++] = 0x59;
        data[i++] = 0x55;
        data[i++] = 0x55;
        return data;
    }

    public static byte[] readData(int index) {
        byte[] data = new byte[14];
        int i = 0;
        data[i++] = (byte) 0xaa;
        data[i++] = (byte) 0x55;
        data[i++] = (byte) 0x47;
        data[i++] = 0x45;
        data[i++] = 0x54;
        data[i++] = 0x44;
        data[i++] = 0x53;
        data[i++] = 0x50;
        data[i++] = 0x54;
        data[i++] = 0x59;
        data[i++] = 0x55;
        data[i++] = 0x55;
        data[i++] = (byte) index;
//        if (index < 107) {
//            data[i++] = 0x00;
//            data[i++] = (byte) (index); //00-99, 100-223
//        } else {
//            data[i++] = 0x01;
//            data[i++] = (byte) (index - 107);
//        }
        YzDebug.d("readData:"+ByteUtil.bytesToHexString(data));
        return data;
    }

    public static byte[] resetApp() {
        byte[] buffer = new byte[]{(byte) 0xaa, (byte) 0x55, (byte) 0xaa, (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
        YzDebug.d("resetApp:"+ByteUtil.bytesToHexString(buffer));
        return buffer;
    }

    public static byte[] resetXover() {
        byte[] buffer = new byte[]{(byte) 0xaa, (byte) 0x55, 0x33, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
        YzDebug.d("resetXover:"+ByteUtil.bytesToHexString(buffer));
        return buffer;
    }

    public static byte[] resetXoverHighPass() {
        //7265736574ca6869676870617373
        byte[] buffer = com.qztech.sdk.utils.ByteUtil.hexToBytes("7265736574ca6869676870617373");
        YzDebug.d("resetXover:"+ ByteUtil.bytesToHexString(buffer));
        return buffer;
    }

    public static byte[] resetXoverLowPass() {
        //7265736574ca6c6f777061737300
        byte[] buffer = com.qztech.sdk.utils.ByteUtil.hexToBytes("7265736574ca6c6f777061737300");
        YzDebug.d("resetXover:"+ ByteUtil.bytesToHexString(buffer));
        return buffer;
    }

    public static byte[] setMode(boolean isSource) {
        byte[] buffer = new byte[]{(byte) 0xaa, (byte) 0x55, (byte) 0xaa, (byte) 0x82, isSource ? (byte) 0xc1 : (byte) 0xc2, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0xff, isSource ? (byte) 0x4e : (byte) 0x4d, 0x7d, 0x55};
//        byte[] buffer = new byte[]{(byte) 0xaa, (byte) 0x55, (byte) 0xaa, (byte) 0x82, isSource ? (byte) 0xc1 : (byte) 0xc2, 0x00, 0x00, 0x00, 0x00, 0x00,0x00,0x00, 0x00, 0x00,0x00,  (byte) 0xff, isSource ? (byte) 0x4e : (byte) 0x4d, 0x7d, 0x55};
//        byte[] buffer = new byte[]{(byte) 0xaa, (byte) 0x55, (byte) 0xaa, (byte) 0x82, isSource ? (byte) 0xc1 : (byte) 0xc2, 0x00, 0x00, 0x00, 0x00, 0x00,0x00,0x00, 0x00, 0x00,  (byte) 0xff,  (byte) 0x4e , 0x7d, 0x55};
//        byte[] buffer = new byte[]{(byte) 0xaa, (byte) 0x55, (byte) 0xaa, (byte) 0x82, isSource ? (byte) 0xc1 : (byte) 0xc2, 0x00, 0x00, 0x00, 0x00, 0x00,  (byte) 0xff,  (byte) 0x4e , 0x7d, 0x55};
//        byte[] buffer = new byte[]{(byte) 0xaa, (byte) 0x82, isSource ? (byte) 0xc1 : (byte) 0xc2, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00,  (byte) 0xff,  0x4e , 0x7d, 0x55};
//        byte[] buffer = new byte[]{(byte) 0xaa, (byte) 0x82, isSource ? (byte) 0xc1 : (byte) 0xc2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0xff, (byte) (isSource ? 0x4e : 0x4d), 0x7d, 0x55};
//        byte[] buffer = new byte[]{(byte) 0xaa, (byte) 0x82, isSource ? (byte) 0xc1 : (byte) 0xc2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,(byte) 0xff, (byte) (isSource ? 0x4e : 0x4d), 0x7d, 0x55};
        YzDebug.d("setMode:"+ ByteUtil.bytesToHexString(buffer));
        return buffer;
    }
}
